package com.wzw.springboot.principle.use.security.infrastructure.model;

import com.alibaba.ttl.TransmittableThreadLocal;

/**
 * 登录用户
 *
 * @author Wangzhiwen
 */
public class SecurityUserHolder {

    private SecurityUserHolder() {

    }

    private static final ThreadLocal<SecurityUser> CONTEXT_USER = new TransmittableThreadLocal<>();

    public static void set(SecurityUser securityUser) {
        CONTEXT_USER.set(securityUser);
    }

    public static SecurityUser get() {
        return CONTEXT_USER.get();
    }

    public static void clean() {
        CONTEXT_USER.remove();
    }

    public static Long getCurrentUserId() {
        return get().getId();
    }
}
